<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BUIThemedControl
 *
 * @author jianfeng
 */
class BUIThemedControl extends BUIControl {

    //put your code here
    const Theme_M_Bootstrap = 'mb_bootstrap';
    const Theme_PC_Bootstrap = 'pc_bootstrap';
    const Theme_M_JQM = 'jqm_wechat';

    public function getAjaxLink($name, $data = array(), $sender = NULL, $route = 'site/index', $updateControl = NULL) {
        $theme = Blyn::app()->getUIManager()->getTheme();
        if (!is_array($data)) {
            $data = array();
        }
        $data['theme'] = $theme;
        if ($theme == self::Theme_M_JQM || $theme == self::Theme_M_Bootstrap) {
            $data['dv'] = 'wx';
            $data['sp'] = Blyn::app()->getActiveSpace()->getId();
            $data['op'] = Blyn::app()->getActiveOperation()->getId();
        }
        return parent::getAjaxLink($name, $data, $sender, $route, $updateControl);
    }

    public function getAjaxLinkUrl($linkId, $updateControl = NULL, $data = array(), $route = 'site/index', $sender = null) {
        if (!is_array($data)) {
            $data = array();
        }
        $theme = Blyn::app()->getUIManager()->getTheme();
        $data['theme'] = $theme;
        if ($theme == self::Theme_M_JQM || $theme == self::Theme_M_Bootstrap) {
            $data['dv'] = 'wx';
            $data['sp'] = Blyn::app()->getActiveSpace()->getId();
            $data['op'] = Blyn::app()->getActiveOperation()->getId();
        }
        return parent::getAjaxLinkUrl($linkId, $updateControl, $data, $route, $sender);
    }

    public function getAjaxScript($name, $data = array(), $sender = NULL, $route = 'site/index', $updateControl = NULL) {
        if (!is_array($data)) {
            $data = array();
        }
        $theme = Blyn::app()->getUIManager()->getTheme();
        $data['theme'] = $theme;
        if ($theme == self::Theme_M_JQM || $theme == self::Theme_M_Bootstrap) {
            $data['dv'] = 'wx';
            $data['sp'] = Blyn::app()->getActiveSpace()->getId();
            $data['op'] = Blyn::app()->getActiveOperation()->getId();
        }
        return parent::getAjaxScript($name, $data, $sender, $route, $updateControl);
    }

    public function getLinkUrl($name = null, $params = array(), $sender = null, $route = 'site/index', $data = array(), $ampersand = '&') {
        if (isset($params['theme']))
            $theme = $params['theme'];
        else
            $theme = Blyn::app()->getUIManager()->getTheme();
        $spaceId = Blyn::app()->getActiveSpace()->getId();
        if ($theme == self::Theme_M_JQM || $theme == self::Theme_M_Bootstrap) {
            $params['dv'] = 'wx';
            $params['sp'] = $spaceId;
            $params['op'] = Blyn::app()->getActiveOperation()->getId();
        }
        $params['theme'] = $theme;
        return parent::getLinkUrl($name, $params, $sender, $route, $data, $ampersand);
    }

}
